from typing import List
import collections
from algorithm import dfs_topology_sort


class Solution:
    def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]:
        indegrees = [0] * numCourses
        adjs = collections.defaultdict(list)
        for v, u in prerequisites:
            indegrees[v] += 1
            adjs[u].append(v)
        result = dfs_topology_sort(numCourses, adjs, indegrees)
        return result


solution = Solution()
print(solution.findOrder(7, [[0,1],[0,2],[0,5],[1,3],[1,4],[2,4],[2,5], [4,0]]))
